home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 151-175 / disk_166 / stevie / source / os2.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  135 lines

  1. /*
  2.  * OS/2 System-dependent routines. 
  3.  */
  4.  
  5. #include "stevie.h"
  6.  
  7. /*
  8.  * inchar() - get a character from the keyboard 
  9.  */
  10. char
  11. inchar()
  12. {
  13.     int             c;
  14.  
  15.     flushbuf();            /* flush any pending output */
  16.  
  17.     c = getch();
  18.     if (c == EOF)        /* EOF used like \n, so just assign it */
  19.     c = '\n';
  20.  
  21.     return ((char) c);
  22. }
  23.  
  24. #define    BSIZE    2048
  25. static char     outbuf[BSIZE];
  26. static int      bpos = 0;
  27.  
  28. flushbuf()
  29. {
  30.     if (bpos != 0)
  31.     write(1, outbuf, bpos);
  32.     bpos = 0;
  33. }
  34.  
  35. /*
  36.  * Macro to output a character. Used within this file for speed. 
  37.  */
  38. #define    outone(c)    outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  39.  
  40. /*
  41.  * Function version for use outside this file. 
  42.  */
  43. void
  44. outchar(c)
  45.     char            c;
  46. {
  47.     outbuf[bpos++] = c;
  48.     if (bpos >= BSIZE)
  49.     flushbuf();
  50. }
  51.  
  52. void
  53. outstr(s)
  54.     char           *s;
  55. {
  56.     while (*s) {
  57.     outone(*s++);
  58.     }
  59. }
  60.  
  61. void
  62. beep()
  63. {
  64.     if (RedrawingDisabled)
  65.     return;
  66.  
  67.     outone('\007');
  68. }
  69.  
  70. sleep(n)
  71.     int             n;
  72. {
  73.     extern far pascal DOSSLEEP();
  74.  
  75.     DOSSLEEP(1000L * n);
  76. }
  77.  
  78. void
  79. delay()
  80. {
  81.     DOSSLEEP(500L);
  82. }
  83.  
  84. void
  85. windinit()
  86. {
  87.     Columns = 80;
  88.     P(P_LI) = Rows = 25;
  89. }
  90.  
  91. void
  92. windexit(r)
  93.     int             r;
  94. {
  95.     flushbuf();
  96.     exit(r);
  97. }
  98.  
  99. void
  100. windgoto(r, c)
  101.     int             r, c;
  102. {
  103.     r += 1;
  104.     c += 1;
  105.  
  106.     /*
  107.      * Check for overflow once, to save time. 
  108.      */
  109.     if (bpos + 8 >= BSIZE)
  110.     flushbuf();
  111.  
  112.     outbuf[bpos++] = '\033';
  113.     outbuf[bpos++] = '[';
  114.     if (r >= 10)
  115.     outbuf[bpos++] = r / 10 + '0';
  116.     outbuf[bpos++] = r % 10 + '0';
  117.     outbuf[bpos++] = ';';
  118.     if (c >= 10)
  119.     outbuf[bpos++] = c / 10 + '0';
  120.     outbuf[bpos++] = c % 10 + '0';
  121.     outbuf[bpos++] = 'H';
  122. }
  123.  
  124. FILE           *
  125. fopenb(fname, mode)
  126.     char           *fname;
  127.     char           *mode;
  128. {
  129.     FILE           *fopen();
  130.     char            modestr[16];
  131.  
  132.     sprintf(modestr, "%sb", mode);
  133.     return fopen(fname, modestr);
  134. }
  135.